home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
ParamRAM guard.sit
/
ParamRAM guard
/
PRAM reset.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-13
|
3KB
|
85 lines
/*
***********************************************************************
*
* PRAM Resetter
* This INIT resets the PRAM and extended PRAM from the saved settings,
* 'HEXA' resource named "Standard PRAM". See "PRAM save.cc" as to what PRAM
* is and how it's read into the resource.
*
* Be sure to make the present INIT resource locked (Look into the
* "Set project type..." menu).
*
* There should be only one function within this file. Note, that when compiling
* a code resource, the compiler generates "call offset(A4)" type instructions
* when processing function calls. Beware, A4 generally is not set when the code
* resource (especially INIT) is called. So, either set up A4 at the very beginning,
* or forget about functions. Note, that inlines are OK: they are just rolled
* out into the code, no call instruction is actually generated.
*
* Always make sure that the code is using standard LINK/UNLK sequence of
* commands to set up the frame, even if the code doesn't use temporary
* (automatic, in C jargon) variables. Setting standard frame is necessary if the
* code uses any of the system/toolbox traps.
* (which strangely assume that A6 contains a valid frame pointer).
* Note, if the compiler does not produce standard LINK/UNLK sequence,
* inserting "asm { nop }" at the very beginning of the program usually helps.
*
***********************************************************************
*/
#include "PRAM Resource.h"
//#include <OsUtils.h>
// This is
// MOVE.L (A7)+,D0 size -> lo word of d0
// MOVEA.L (A7)+,A0 where -> A0
// _WriteXPRam
static pascal void write_extended_PRAM
(const char * where, const short offset, const short size) =
{0x201F, 0x205F, 0xA052};
// LEA.L $01f8,a0
// MOVEQ #$FF,d0
// _WriteParam
static short WritePRAM(void) =
{0x41F8, 0x01F8, 0x70FF, 0xA038};
// MOVE.L (a7),d0
static int failed_init(const int failed_line) =
{ 0x2017 };
#define assert_init(X) { if(X); else return failed_init(__LINE__); }
short main(void)
{
struct PRAMSettings ** res_handle;
asm { nop } // It forces generating "LINK A6" to set up a frame
assert_init( (res_handle =
(struct PRAMSettings**)Get1NamedResource('HEXA',"¥pStandard PRAM"))
!= nil );
assert_init( SizeResource((Handle)res_handle) == sizeof(struct PRAMSettings) );
assert_init( (unsigned char)((*res_handle)->PRAM).valid == 0xA8 );
*(GetSysPPtr()) = (*res_handle)->PRAM; // Copying PRAM settings into the Lo Globals
assert_init( WritePRAM() == noErr );
write_extended_PRAM((char *)(*res_handle)->extended_PRAM.layout.parm1,
(char *)(*res_handle)->extended_PRAM.layout.parm1 - (char *)(*res_handle)->extended_PRAM.body,
sizeof((*res_handle)->extended_PRAM.layout.parm1));
write_extended_PRAM((char *)(*res_handle)->extended_PRAM.layout.parm2,
(char *)(*res_handle)->extended_PRAM.layout.parm2 - (char *)(*res_handle)->extended_PRAM.body,
sizeof((*res_handle)->extended_PRAM.layout.parm2));
return noErr;
}